//创建 hooks 生成逻辑
import fs from "fs";
import path from "path";
const clc = require('cli-color');

export function createHook(name: string) {
  const hookDir = path.join(process.cwd(), "src/hooks");
  if (!fs.existsSync(hookDir)) fs.mkdirSync(hookDir, { recursive: true });

  const hookTemplate = `
import { ref } from "vue";

export function use${name}() {
  const state = ref(false);
  
  function toggle() {
    state.value = !state.value;
  }
  
  return { state, toggle };
}
`;

  const filePath = path.join(hookDir, `use${name}.ts`);
  if (fs.existsSync(filePath)) {
    console.log(clc.red("Hook 已存在！"));
    return;
  }

  fs.writeFileSync(filePath, hookTemplate);
  console.log(clc.green(`Hook use${name} 创建成功！`));
}
